﻿using Cxuu.Common;
using Cxuu.Models;
using Cxuu.Service;
using Microsoft.AspNetCore.Mvc;
using PetaPoco;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Cxuu.Web.Home
{
    [Area("Home")]
    public class VideoController : Base
    {
        private readonly ExtVideoService _extVideoService;
        private readonly ExtVideoCateService _extVideoCateService;

        public VideoController(ExtVideoService extVideoService, ExtVideoCateService extVideoCateService)
        {
            _extVideoService = extVideoService;
            _extVideoCateService = extVideoCateService;
        }

        [HttpGet]
        public async Task<IActionResult> IndexAsync(int page = 1)
        {
            Page<ViewExtVideoCateAndContent> infoList = await _extVideoService.GetListByCidAsync(0, page, 20);
            return View(infoList);
        }
        [HttpGet]
        public async Task<IActionResult> ListAsync(int id, int page = 1)
        {
            if (id < 1)
            {
                return Ok("请勿非法输入！");
            }
            ExtVideoCate cateInfo = await _extVideoCateService.GetOneAsync(id);
            Page<ViewExtVideoCateAndContent> infoList = await _extVideoService.GetListByCidAsync(id, page, cateInfo.Num);
            ViewBag.cateInfo = cateInfo;
            if (cateInfo.Theme != null)
                return View(cateInfo.Theme,infoList);
            else
                return View(infoList);
        }
        [HttpGet]
        public async Task<IActionResult> InfoAsync(int? id)
        {
            if (id == null)
            {
                return Ok("请勿非法输入！");
            }
            ViewExtVideoCateAndContent article = await _extVideoService.GetAsync(id);
            if (article == null)
            {
                return NotFound();
            }
            ExtVideoCate cateInfo = await _extVideoCateService.GetOneAsync(article.Cid);
            ViewBag.info = article;
            ViewBag.cateInfo = cateInfo;
            return View();
        }

    }
}
